package top.mataiji.manager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import mataiji.config.util.Result;
import top.mataiji.manager.pojo.vo.CartVo;
import top.mataiji.manager.service.CartService;

import java.util.List;

/**
 * @Auther: zhaoss
 * @Date: 2021/3/22 - 03 - 22 - 15:54
 * @Description: top.mataiji.manager.controller
 * @version: 1.0
 */
@RestController
@RequestMapping("cart")
public class CartController {

    @Autowired
    CartService cartService;

    @RequestMapping("list")
    public List<CartVo> findAllCartByUserId(Integer userId){
        return cartService.findAllUserId(userId);
    }

    @DeleteMapping("delete")
    public Result deleteCartById(Integer id){
        System.out.println(id);
        Integer resule =  cartService.deleteCartById(id);
        if(resule!=null&&resule>0){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

    @RequestMapping("change")
    public Result change(Integer teid,Integer num){
        Integer result =  cartService.change(teid,num);
        if (result!=null&&result!=0){
            return Result.success("");
        }
        return Result.error("");
    }

}
